<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>个人中心|蜗牛宠物领养平台</title>

    <link rel="shortcut icon" th:href="@{/asserts/images/favicon.ico}" type="image/x-icon"/>
    <!-- Bootstrap的css -->
    <link rel="stylesheet" th:href="@{/asserts/bootstrap3.4.1/css/bootstrap.min.css}">
    <!-- jQuery本地-->
    <script th:src="@{/asserts/js/jQuery-3.6.0.js}"></script>
    <!-- 加载本地js -->
    <script th:src="@{/asserts/bootstrap3.4.1/js/bootstrap.min.js}"></script>
    <!-- 加载common.css -->
    <link rel="stylesheet" th:href="@{/asserts/css/common.css}"/>
    <!-- 加载页头页尾css -->
    <link rel="stylesheet" th:href="@{/asserts/css/top.css}"/>
    <link rel="stylesheet" th:href="@{/asserts/css/foot.css}"/>
    <!-- 加载本地css -->
    <link rel="stylesheet" th:href="@{/asserts/css/personal.css}"/>
    <!-- 加载页头页尾js -->
    <script th:src="@{/asserts/js/top.js}"></script>
    <!-- 加载本地js-->
    <script th:src="@{/asserts/js/personal.js}"></script>
    <!-- 省市区三级插件 -->
    <script th:src="@{/asserts/js/distpicker.js}"></script>
    <!--加载验证插件-->
    <script th:src="@{/asserts/validator/js/bootstrapValidator.js}"></script>
    <link rel="stylesheet" th:href="@{/asserts/validator/css/bootstrapValidator.css}"/>
</head>
<body>
<!-- 页头 -->
<nav th:replace="nav::headerBar"></nav>
<div class="container">
    <div class="header">
        <span>我的头像</span>
    </div>
    <div class="avatar" data-toggle="tooltip" data-placement="top" title="点击可上传头像">
        <div class="col-md-6 imgdiv">
            <input type="file" id="imagefile" name="file" onchange="uploadPic()"/>
            <img id="showImg" th:src="${session.loginUser.pic}" alt="我的头像" style="width: 250px;  border-radius: 25px;">
        </div>
    </div>

    <!--------------------------------------------未发送志愿者申请显示----------------------------------------------------->
    <div class="col-md-4 col-sm-12"
         th:if="${session.loginUser.volunteerStatus==null}">
        <div class="contact-form bottom">
            <h2>加入我们</h2>
            <form id="applyForm">
                <h5>申请成为我们的志愿者，让我们共同守护流浪宠物</h5>
                <hr/>
                <h5>"三个臭皮匠,顶一个诸葛亮"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;---歇后语</h5>
                <hr/>
                <div class="form-group">
                    <textarea name="message" id="message" required="required" class="form-control" rows="8"
                              placeholder="在这里，你可以输入你的申请理由"></textarea>
                </div>
                <div class="form-group">
                    <button type="submit" name="submit" class="btn btn-submit" onclick="apply(event)">申请</button>
                </div>
            </form>
        </div>
    </div>

    <!---------------------------------------已发送志愿者申请，待管理员审核显示----------------------------------------------->
    <div class="col-md-4 col-sm-12"
         th:if="${session.loginUser.volunteerStatus==0}">
        <div class="contact-form bottom">
            <h3>我的志愿者申请信息</h3>
            <hr/>
            <form id="applyForm2">
                <h5>您已发送您的志愿者申请信息，请等<font color="#deb887">待</font>管理员<font color="#deb887">审核</font></h5>
                <hr/>
                <h5>您也可以点击下面的修改申请按钮修改您的个人信息</h5>
                <hr/>
                <div class="form-group">
                    <textarea name="message" id="message2" required="required" class="form-control" rows="8"
                              placeholder="在这里，你可以输入你的申请理由" disabled></textarea>
                </div>
                <div class="form-group">
                    <button id="priEditButton" class="btn btn-primary" onclick="apply2Pri(event)">修改申请</button>
                    <button id="doEditButton" class="btn btn-warning" type="submit" onclick="apply2(event)" style="display: none">确认修改</button>
                </div>
            </form>
        </div>
    </div>

    <!---------------------------------------已经是志愿者----------------------------------------------->
    <div class="col-md-4 col-sm-12"
         th:if="${session.loginUser.volunteerStatus==1}">
        <div class="contact-form bottom">
            <h2>恭喜成为我们的一员</h2>
            <h5>您现在可以使用您的账号登录我们的<a href="http://127.0.0.1:20002" style="color: red">管理系统</a>
                <hr />参与<font color="#00cdc1">领养管理</font>、<font color="#6495ed">团队管理</font>和<font color="#ffd700">文章管理</font>中</h5>
            <hr/>
                <h5>感谢您对我们的支持</h5>
        </div>
    </div>

    <!---------------------------------------申请已被拒绝----------------------------------------------->
    <div class="col-md-4 col-sm-12"
         th:if="${session.loginUser.volunteerStatus==2}">
        <div class="contact-form bottom">
            <h2>我的志愿者申请信息</h2>
            <hr/>
            <form id="applyForm3">
                <h5>很遗憾，你的志愿者申请<font color="red">未</font>通<font color="red">过</font>管理员<font color="red">审</font>核</h5>
                <hr/>
                <h5>您也可以点击下面的申请按钮再次申请</h5>
                <hr/>
                <div class="form-group">
                    <textarea name="message" id="message3" required="required" class="form-control" rows="8"
                              placeholder="在这里，你可以输入你的申请理由" disabled></textarea>
                </div>
                <div class="form-group">
                    <button id="priEditButton2" class="btn btn-submit" onclick="apply3Pri(event)">申请</button>
                    <button id="doEditButton2" class="btn btn-submit" type="submit" onclick="apply3(event)" style="display: none">确认申请</button>
                </div>
            </form>
        </div>
    </div>
    <div class="col-md-12 mt15">

        <!-- ========================= 详细信息 收藏 消息========================== -->
        <div class="container no-padding center">
            <div id="showAll">
                <ul class="nav nav-tabs">
                    <li role="presentation" class="active" id="per"><a href="#" title="1">个人中心</a></li>
                    <li role="presentation" th:if="${petList}==null"><a th:href="@{/user/showPetColList}">我的收藏</a></li>
                    <li role="presentation" th:if="${petList}!=null"><a href="#" title="2" id="col">我的收藏</a></li>
                    <li role="presentation" th:if="${msgList}==null"><a th:href="@{/user/myMessage}">我的消息</a></li>
                    <li role="presentation" th:if="${msgList}!=null"><a href="#" title="3">我的消息</a></li>
                </ul>
                <!-- 账号详细信息 -->
                <div class="account-detail">
                    <div id="form-account-detail" class="form-horizontal mt15">
                        <div class="col-xs-6">
                            <div>账号信息</div>
                            <!----------------------------------------------------密码修改表单---------------------------------------------------->
                            <form id="changePassword" class="form-horizontal"
                                  data-bv-message="This value is not valid"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">账号:</label>
                                    <div class="col-xs-6">
                                        <input type="text" class="form-control" name="username"
                                               th:value="${session.loginUser.username}"
                                               data-bv-message="The username is not valid"
                                               required
                                               data-bv-notempty-message="The username is required and cannot be empty"
                                               pattern="^[a-zA-Z0-9]+$"
                                               data-bv-regexp-message="The username can only consist of alphabetical and digits"
                                               data-bv-stringlength="true" data-bv-stringlength-min="6"
                                               data-bv-stringlength-max="30"
                                               data-bv-stringlength-message="The username must be more than 6 and less than 30 characters long"
                                               data-bv-different="true" data-bv-different-field="password"
                                               data-bv-different-message="The username and password cannot be the same as each other"
                                               disabled>
                                    </div>
                                </div>
                                <div class="form-group" id="password">
                                    <label class="col-sm-2 control-label">密码:</label>
                                    <div class="col-xs-6">
                                        <input type="password" class="form-control" name="password"
                                               th:value="${session.loginUser.password}"
                                               required data-bv-notempty-message="密码不能为空"
                                               pattern="^[a-zA-Z0-9]{6,16}$" data-bv-regexp-message="密码应该是6-16位的非中文字符"
                                               data-bv-identical="true" data-bv-identical-field="password2"
                                               data-bv-identical-message="两次输入密码不一致"
                                               data-bv-different="true" data-bv-different-field="username"
                                               data-bv-different-message="密码不能和用户名相同"
                                               disabled/>
                                    </div>
                                </div>
                                <div class="form-group" style="display: none" id="password2">
                                    <label class="col-sm-2 control-label">密码重输:</label>
                                    <div class="col-xs-6">
                                        <input type="password" class="form-control" name="password2"
                                               th:value="${session.loginUser.password}"
                                               required data-bv-notempty-message="密码重输不能为空"
                                               data-bv-identical="true" data-bv-identical-field="password"
                                               data-bv-identical-message="两次输入密码不一致"
                                               data-bv-different="true" data-bv-different-field="username"
                                               data-bv-different-message="密码不能和用户名相同"
                                        />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-6 col-xs-offset-2">
                                        <button class="btn btn-info" onclick="editPassword()" id="priEditPassButton">
                                            修改密码
                                        </button>
                                    </div>
                                    <div class="col-xs-6 col-xs-offset-2">
                                        <button class="btn btn-danger" id="editPassButton" style="display: none"
                                                type="submit" onclick="doEditPassword(event)">确认修改
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!----------------------------------------------------个人信息修改表单---------------------------------------------------->
                        <div class="col-xs-6">
                            <div>个人信息</div>
                            <form id="changeInfo" class="form-horizontal"
                                  data-bv-message="请输入内容"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                                <div class="form-group">
                                    <input id="uid" th:value="${session.loginUser.id}" hidden>
                                    <label class="col-xs-2 control-label">昵称:</label>
                                    <div class="col-xs-6">
                                        <input name="name" type="text" class="form-control"
                                               required data-bv-notempty-message="昵称不能为空"
                                               pattern="^[\u4E00-\u9FA5A-Za-z0-9_]+$"
                                               data-bv-regexp-message="昵称用中文字母或数字组成"
                                               data-bv-stringlength="true" data-bv-stringlength-min="2"
                                               data-bv-stringlength-max="10" data-bv-stringlength-message="昵称长度2-10位"
                                               th:value="${session.loginUser.name}" disabled>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">电话:</label>
                                    <div class="col-xs-6">
                                        <input name="telephone" type="text" class="form-control"
                                               pattern="^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$"
                                               data-bv-regexp-message="请输入正确的电话号码"
                                               th:value="${session.loginUser.telephone}" disabled>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">邮箱:</label>
                                    <div class="col-xs-6">
                                        <input name="email" type="email" class="form-control"
                                               data-bv-emailaddress-message="请输入正确的邮箱地址"
                                               th:value="${session.loginUser.email}" disabled>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">年龄:</label>
                                    <div class="col-xs-6">
                                        <input name="age" type="text" class="form-control" step="1"
                                               min="10" data-bv-greaterthan-inclusive="false"
                                               data-bv-greaterthan-message="年龄最小10岁"
                                               max="100" data-bv-lessthan-inclusive="true"
                                               data-bv-lessthan-message="年龄不能超过100岁"
                                               th:value="${session.loginUser.age}" disabled>
                                    </div>
                                </div>
                                <div class="form-group" th:if="${session.loginUser.gender}==0">
                                    <label class="col-xs-2 control-label" disabled>性别:</label>
                                    &nbsp; &nbsp;
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="0"
                                               checked> 男
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="1"
                                               disabled required data-bv-notempty-message="性别必选">
                                        女
                                    </label>
                                </div>
                                <div class="form-group" th:if="${session.loginUser.gender}==1">
                                    <label class="col-xs-2 control-label" disabled>性别:</label>
                                    &nbsp; &nbsp;
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" value="0" disabled> 男
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" value="1" checked required
                                               data-bv-notempty-message="性别必选"> 女
                                    </label>
                                </div>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">地址:</label>
                                    <div class="col-xs-6">
                                        <input name="address0" type="hidden" class="form-control"
                                               th:value="${session.loginUser.address}">
                                    </div>
                                </div>
                                <div data-toggle="distpicker" data-placeholder="false" id="target">
                                    <select id="p" class="form-control" style="width:100px;margin-left: 7em;"
                                            disabled></select>
                                    <select id="c" class="form-control" style="width:150px;margin-left: 7em;"
                                            disabled></select>
                                    <select id="pc" class="form-control" style="width:200px;margin-left: 7em;"
                                            disabled></select>

                                </div>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label"></label>
                                    <div class="col-xs-6">
                                        <input name="leftover" type="text" class="form-control"
                                               required data-bv-notempty-message="地址不能为空"
                                               style="width:250px;" disabled/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-xs-6 col-xs-offset-2">
                                        <button id="priModify" class="btn btn-info"
                                                th:onclick="priModifyUserInfo()">
                                            修改信息
                                        </button>
                                        <!--阻止表单事件-->
                                        <button id="doModify" class="btn btn-info" type="submit"
                                                onclick="priDoModifyUserInfo(event)"
                                                style="display: none">保存修改
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

                <!-- 收藏列表 -->
                <div class="account-collection" style="display: none;">
                    <h1>我的收藏列表</h1>
                    <div class="row">
                        <div class="col-sm-6 col-md-4" th:each="pet:${petList}">
                            <div class="thumbnail">
                                <img th:src="'https://woniu-adopt.oss-cn-hangzhou.aliyuncs.com/adoptImages/'+${pet.image}"
                                     alt="..." class="img-circle" style="width: 250px;height: 250px;">
                                <div class="caption">
                                    <h3 th:text="${pet.name}"></h3>
                                    <p th:if="${pet.state==0}">未被领养</p>
                                    <p th:if="${pet.state==1}" style="color: red;">已被领养</p>
                                    <p>
                                        <button class="btn btn-default" role="button"
                                                th:onclick="'javascript:unCol('+${pet.id}+')'">取消收藏
                                        </button>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 消息列表 -->
                <div class="account-message" style="display: none;">
                    <button th:onclick="'javascript:allRead()'">全部已读</button>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>状态</th>
                            <th>接收时间</th>
                            <th>消息内容</th>
                        </tr>
                        </thead>
                        <tbody th:each="m:${msgList}">
                        <tr>
                            <th>
                                <p th:if="${m.messageState==0}" style="color: red;">未读</p>
                                <p th:if="${m.messageState!=0}">已读</p>
                            </th>
                            <td><p th:text="${#dates.format(m.insertTime,'yyyy-MM-dd HH:mm:ss')}"></p></td>
                            <td><p th:text="${m.message}"></p></td>
                        </tr>
                        </tbody>
                    </table>
                    <div >


                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<!-- 页尾 -->
<footer th:replace="nav::footBar"></footer>
</body>
<script>
    //warning:放到js文件里就跑不动了!!!!!
    function apply(event) {
        event.preventDefault();
        let message= $("#message").val();
        let data = {
            message: message,
            option:0
        }
        let url = '[[@{/user/beVolunteer}]]';
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            dataType: 'json',
            success: res => {
                if (res==0) {
                    alert("申请成功，请等候消息或者修改您的申请信息");
                    location.reload();
                } else {
                    alert("系统错误，请联系管理员");
                    location.reload();
                }
            }
        })
    }
    function apply2Pri(event){
        event.preventDefault();
        $("#priEditButton").hide();
        $("#doEditButton").show();
        $("#message2").attr("disabled",false);
    }
    function apply2(event){
        event.preventDefault();
        let message= $("#message2").val();
        if (message == '') {
            alert("请输入申请理由！");
            return;
        }
        if (message.length < 10 && message.length != 0) {
            alert("请至少输入10字以上的申请理由！");
            return;
        }
        let data = {
            message: message,
            option:1
        }
        let url = '[[@{/user/beVolunteer}]]';
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            dataType: 'json',
            success: res => {
               if (res==1){
                    alert("修改申请信息成功");
                    location.reload();
                } else {
                   alert("系统错误，请联系管理员");
                   location.reload();
               }
            }
        })
    }
    function apply3Pri(event){
        event.preventDefault();
        $("#priEditButton2").hide();
        $("#doEditButton2").show();
        $("#message3").attr("disabled",false);
    }
    function apply3(event){
        event.preventDefault();
        let message= $("#message3").val();
        if (message == '') {
            alert("请输入申请理由！");
            return;
        }
        if (message.length < 10 && message.length !== 0) {
            alert("请至少输入10字以上的申请理由！");
            return;
        }
        let data = {
            message: message,
            option:1
        }
        let url = '[[@{/user/beVolunteer}]]';
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            dataType: 'json',
            success: res => {
               if (res==1){
                    alert("申请成功！请等待管理员审核！");
                    location.reload();
                } else {
                   alert("系统错误，请联系管理员！");
                   location.reload();
               }
            }
        })
    }

    $(document).ready(function () {
        $('#changePassword').bootstrapValidator();
        $('#changeInfo').bootstrapValidator();
        //反显申请理由
        if('[[${session.loginUser.volunteerStatus}]]'==0||'[[${session.loginUser.volunteerStatus}]]'==2){
            let url='[[@{/user/getApplyMessage}]]';
            console.log('[[${session.loginUser.volunteerStatus}]]');
            $.ajax({
                url:url,
                type:"get",
                success:res=>{
                    if(res!=null){
                        $("#message2").val(res);
                        $("#message3").val(res);
                    }
                }
            })
        }


    });

    function unCol(pid) {
        let uid = '[[${session.loginUser.id}]]';
        let url = '[[@{/pet/collectionDel}]]';
        $.ajax({
            url: url,
            data: {
                uid: uid,
                pid: pid
            },
            type: 'get',
            dataType: 'json',
            success: function (res) {
                if (res == 1) {
                    alert("取消收藏成功！");
                    location.href = '[[@{/user/showPetColList}]]';
                } else {
                    alert("取消收藏失败，请稍后操作！");
                }
            },
            error: function (xhr, errorMessage, e) {
                alert("操作失败,系统错误");
            }
        })
    }

    function editPassword() {
        $("input[name='password']").attr("disabled", false);
        $("#password2").show();
        $("#priEditPassButton").hide();
        $("#editPassButton").show();
    }

    function doEditPassword(event) {
        event.preventDefault();
        //如果密码未作修改，则提示未修改密码，刷新页面
        if( $("input[name='password']").val()=='[[${session.loginUser.password}]]'){
            alert('您未作任何修改！');
            location.reload();
            return;
        }
        let url = 'http://localhost:9009/user/modify';
        $.ajax({
            url: url,
            type: "post",
            data: {
                id: '[[${session.loginUser.id}]]',
                username: $("input[name='username']").val(),
                password: $("input[name='password']").val()
            },
            dataType: "json",
            success: function (msg) {
                if (msg == 1) {
                    alert("修改成功,请重新登录!");
                    location.href = "login.html";
                } else {
                    alert("修改失败");
                }
            }
        })
    }

    function uploadPic() {
        var formData = new FormData();
        formData.append("file", $("#imagefile")[0].files[0]);
        $.ajax({
            url: "http://localhost:9009/oss/upload",
            type: "post",
            data: formData,
            contentType: false,
            processData: false,
            success: function (result) {
                if (result != 'fail') {
                    $("#showImg").attr("src", result);
                    let pic = result.substring(result.lastIndexOf('/') + 1);
                    doModifyUserInfo(pic);
                } else {
                    alert("图片上传失败")
                }
            }
        })
    }

    let province;
    let city;
    let district;
    getpc();
    $('#target').distpicker({
        province: province,
        city: city,
        district: district
    });

    function priModifyUserInfo() {
        //先把input设置成可编辑
        $("input[type='text']").not("input[name='username']").attr("disabled", false);
        $("input[type='radio']").attr("disabled", false);
        $("input[type='email']").attr("disabled", false);
        $("select").attr("disabled", false);
        document.getElementById("doModify").style.display = 'block';
        document.getElementById("priModify").style.display = 'none';
        console.log($("select[name='address0']").val());
    }

    function priDoModifyUserInfo(event) {
        event.preventDefault();
        doModifyUserInfo();
    }

    function doModifyUserInfo(pic) {
        let data = {
            id: $("#uid").val(),
            pic: pic,
            username: $("input[name='username']").val(),
            name: $("input[name='name']").val(),
            telephone: $("input[name='telephone']").val(),
            email: $("input[name='email']").val(),
            gender: $("input:radio:checked").val(),
            age: $("input[name='age']").val(),
            address: $("#p").val() + $("#c").val() + $("#pc").val() + $("input[name='leftover']").val()
        };
        let url = 'http://localhost:9009/user/modify';
        $.ajax({
            url: url,
            type: "post",
            data: data,
            dataType: "json",
            success: function (msg) {
                if (msg == 1) {
                    alert("修改成功!");
                    location.reload();
                } else {
                    alert("修改失败");
                }
            }
        })
    }

    function getpc() {
        let address = $("input[name='address0']").val();
        let leftover = '';
        let start = 0;
        let end = 1;
        let count = 0;//匹配 次数
        let pflag = 1;//默认province是省
        for (let i = start; i < address.length; i++) {
            if (count == 0) {
                if (address.substring(start, end)[end - start - 1] == '省') {
                    count++;
                    province = address.substring(start, end);
                    start = end;
                    console.log(province)
                } else if (address.substring(start, end)[end - start - 1] == '市') {
                    count++;
                    province = address.substring(start, end);
                    start = end;
                    console.log(province);
                    end++;
                    pflag = 2;
                } else if (address.substring(start, end)[end - start - 1] == '区') {
                    count++;
                    province = address.substring(start, end);
                    start = end;
                    pflag = 3;
                } else {
                    end++;
                }
            } else if (count == 1) {
                if (pflag == 1) {
                    //省下面开始扫描
                    if (address.substring(start, end)[end - start - 1] == '市') {
                        count++;
                        city = address.substring(start, end);
                        start = end;
                        console.log(city);
                    } else if (address.substring(start, end)[end - start - 1] == '区') {
                        count++;
                        city = address.substring(start, end);
                        start = end;
                    } else if (address.substring(start, end)[end - start - 1] == '州') {
                        count++;
                        city = address.substring(start, end);
                        start = end;
                    } else {
                        end++;
                    }
                } else if (pflag == 2) {
                    if (address.substring(start, end)[end - start - 1] == '区' || address.substring(start, end)[end - start - 1] == '县' && address.substring(start, end)[end - start - 1] != '市') {
                        city = address.substring(start, end);
                        start = end;
                        console.log(city);
                        console.log(province)
                        count++;
                    } else {
                        end++;
                    }
                } else if (pflag == 3) {
                    if (address.substring(start, end)[end - start - 1] == '区' || address.substring(start, end)[end - start - 1] == '市') {
                        city = address.substring(start, end);
                        count++;
                        start = end;
                        end++;
                    }
                } else {
                    end++;
                }
            } else if (count == 2) {
                if (address.substring(start, end)[end - start - 1] == '区' || address.substring(start, end)[end - start - 1] == '县' || address.substring(start, end)[end - start - 1] == '市') {
                    district = address.substring(start, end);
                    console.log(district);
                    start = end;
                    leftover = address.substring(start);
                    console.log(leftover);
                    $("input[name='leftover']").val(leftover)
                } else {
                    end++;
                }
            }

        }
    }
    //消息全部已读
    function allRead(){
        let uid = '[[${session.loginUser.id}]]';
        let url = '[[@{/user/readAllMsg}]]';
        $.ajax({
            url: url,
            data: {
                uid: uid
            },
            type: 'get',
            dataType: 'json',
            success: function (res) {
                if (res == 1) {
                    alert("操作成功！");
                    location.href = '[[@{/user/myMessage}]]';
                } else {
                    alert("操作失败，请稍后操作！");
                }
            },
            error: function (xhr, errorMessage, e) {
                alert("操作失败,系统错误");
            }
        })
    }
</script>
</html>
